package top.fengyulou.xiaofeng.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.fengyulou.xiaofeng.config.interceptor.AdminLoginInterceptor;
import top.fengyulou.xiaofeng.config.interceptor.AdminDataInterceptor;
import top.fengyulou.xiaofeng.config.interceptor.CommonDataInterceptor;
import top.fengyulou.xiaofeng.config.interceptor.LoginInterceptor;

import javax.annotation.Resource;

@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;
    @Resource
    private AdminLoginInterceptor adminLoginInterceptor;
    @Resource
    private AdminDataInterceptor adminDataInterceptor;
    @Resource
    private CommonDataInterceptor commonDataInterceptor;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/file/**").addResourceLocations("file:E:\\gitee\\exam\\");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //前台登录拦截器
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/user/**","/logout");
        //后台登录拦截器
        registry.addInterceptor(adminLoginInterceptor)
                .addPathPatterns("/admin/**").excludePathPatterns("/admin/login","/admin/ajax/login");
        //后台数据封装拦截器
        registry.addInterceptor(adminDataInterceptor)
                .addPathPatterns("/admin/**").excludePathPatterns("/admin/login","/admin/ajax/login");
        //前后台通用数据封装拦截器
        registry.addInterceptor(commonDataInterceptor)
                .addPathPatterns("/admin/**","/user/**","/exam/**","/");
    }
}